package com.ymatou.auth.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.auth.parameter.RemoveTokenBean;
import com.ymatou.auth.service.RemoveTokenCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AuthCallService;
import com.ymttest.business.service.UserCallService;

/**
 * 移除认证 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_RemoveToken {
	private static RemoveTokenBean lab;
	private static RemoveTokenCall lac;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("移除认证");
	}

	@Before
	public void caseUp() {
		lab = new RemoveTokenBean();
		lac = new RemoveTokenCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(lac.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_RemoveToken_001() {
		Logger.start(true,"移除认证成功");
		try {
			Map UserMap = UserCallService.registerByMobile();
			String userId = UserMap.get("userid").toString();
			String UserName = UserMap.get("username").toString();
			String ip = UserMap.get("ip").toString();
			Map m = AuthCallService.authLogin(UserName, "123456a","app",ip);
			Logger.comment("登入成功:" + m);
			String accessToken1 = m.get("accessToken").toString();
			lab.setUserid(userId);
			lac.setData(lab);
			Logger.comment("调用删除Token接口");
			lac.callService();
			Thread.sleep(3000);
			Map m2 = AuthCallService.authLogin(UserName, "123456a","app",ip);
			Logger.comment("修改密码后登入成功:" + m2);
			String accessToken2 = m2.get("accessToken").toString();
			Logger.verifyNotEquals(accessToken1, accessToken2, "验证修改密码前后accessToken不一致");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}